package com.ujiuye.listener;

import javax.servlet.http.HttpSessionActivationListener;
import javax.servlet.http.HttpSessionEvent;
import java.io.Serializable;

/**
 * 监听 session活化和钝化的监听器
 *
 * 特殊  不需要加注解
 *
 * 需要实现两个接口HttpSessionActivationListener, Serializable
 */
public class Teacher implements HttpSessionActivationListener, Serializable {

    private String name;
    private int age;

    @Override
    public void sessionWillPassivate(HttpSessionEvent se) {
        //从内存钝化到本地磁盘
        System.out.println("钝化");
        //获取sessionid
        String id = se.getSession().getId();
        System.out.println(id);

    }

    @Override
    public void sessionDidActivate(HttpSessionEvent se) {
        //从本地磁盘将文件活化到内存中
        System.out.println("活化");
        String id = se.getSession().getId();
        System.out.println(id);
    }

    public Teacher() {
    }

    public Teacher(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    @Override
    public String toString() {
        return "Teacher{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }
}
